package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.entity.ShoppingCart;
import com.jiuyi.service.Impl.ShoppingCartServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * DATA: 2022/10/23
 * Author: 晨夕
 */
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartServiceImpl shoppingCartServiceImpl;

    /**
     * 添加订单
     */
    @PostMapping("/add")
    public R addShoppingCart(@RequestBody ShoppingCart shoppingCart,HttpServletRequest request){
        return shoppingCartServiceImpl.addShoppingCart(shoppingCart,request);
    }
    /**
     * 查看购物车
     */
    @GetMapping("/list")
    public R<ShoppingCart> selectShoppingCart(HttpServletRequest request){
        return shoppingCartServiceImpl.selectShoppingCart(request);
    }
    /**
     * 清空购物车
     */
    @DeleteMapping("/clean")
    public R deleteShoppingCart(HttpServletRequest request){
        return shoppingCartServiceImpl.deleteShoppingCart(request);
    }
    /**
     * 减少订单
     */
    @PostMapping("/sub")
    public R subShoppingCart(@RequestBody ShoppingCart shoppingCart,HttpServletRequest request){
        return shoppingCartServiceImpl.subShoppingCart(shoppingCart,request);
    }
}
